const ioioi = require('../main');

function context() {
  return {
    exec : null,
    method : '',
    pass : ''
  };
}

let ioi = new ioioi.mid({debug:true});

let postCheck = (c, name) => {
  if (c.method == 'POST' && c.pass !== 'abc') {
    console.log('  post deny', name);
    return false;
  }
  return true;
};

ioi.use(async (c, next) => {
  console.log('m1 in');
  await next();
  console.log('m1 out');
});

ioi.use(async (c, next) => {
  console.log('  m2 in');
  await next();
  console.log('  m2 out');
}, postCheck, 'm2');

ioi.use(async (c, next) => {
  console.log('    m3 in');
  await next();
  console.log('    m3 out');
}, 'm2');

let b = context();

b.method = 'POST';
b.pass = 'abcd';
b.exec = async (c) => {
  console.log('      I am b');
};

ioi.run(b);
